struct _GtkWidgetPath
{
+ volatile guint ref_count;
+
GArray *elems; /* First element contains the described widget */
};
path = g_slice_new0 (GtkWidgetPath);
path->elems = g_array_new (FALSE, TRUE, sizeof (GtkPathElement));
+ path->ref_count = 1;
return path;
}
}
/**
- * gtk_widget_path_free:
+ * gtk_widget_path_ref:
* @path: a #GtkWidgetPath
*
- * Frees a #GtkWidgetPath.
+ * Increments the reference count on @path.
*
- * Since: 3.0
+ * Returns: @path itself.
+ *
+ * Since: 3.2
+ **/
+GtkWidgetPath *
+gtk_widget_path_ref (GtkWidgetPath *path)
+{
+ g_return_val_if_fail (path != NULL, path);
+
+ g_atomic_int_add (&path->ref_count, 1);
+
+ return path;
+}
+
+/**
+ * gtk_widget_path_unref:
+ * @path: a #GtkWidgetPath
+ *
+ * Decrements the reference count on @path, freeing the structure
+ * if the reference count reaches 0.
+ *
+ * Since: 3.2
**/
void
-gtk_widget_path_free (GtkWidgetPath *path)
+gtk_widget_path_unref (GtkWidgetPath *path)
{
guint i;
g_return_if_fail (path != NULL);
+ if (!g_atomic_int_dec_and_test (&path->ref_count))
+ return;
+
for (i = 0; i < path->elems->len; i++)
{
GtkPathElement *elem;
g_slice_free (GtkWidgetPath, path);
}
+/**
+ * gtk_widget_path_free:
+ * @path: a #GtkWidgetPath
+ *
+ * Decrements the reference count on @path, freeing the structure
+ * if the reference count reaches 0.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_widget_path_free (GtkWidgetPath *path)
+{
+ g_return_if_fail (path != NULL);
+
+ gtk_widget_path_unref (path);
+}
+
/**
* gtk_widget_path_length:
* @path: a #GtkWidgetPath
GtkWidgetPath * gtk_widget_path_new (void);
GtkWidgetPath * gtk_widget_path_copy (const GtkWidgetPath *path);
+GtkWidgetPath * gtk_widget_path_ref (GtkWidgetPath *path);
+void gtk_widget_path_unref (GtkWidgetPath *path);
void gtk_widget_path_free (GtkWidgetPath *path);
char * gtk_widget_path_to_string (const GtkWidgetPath *path);